/**
 * @author Andrew Dashin <dashin@andrewdashin.com>
 */
var MyResetBox = Class.create();
MyResetBox.prototype = Object.extend(new Service(), {
    ERR_EMPTY_LOGIN: '1', 
    ERR_EMPTY_EMAIL: '2', 
    ERR_NONEXISTENT_USER: '3', 
	initialize: function () {
		// init action
	},
    
    bind: function (oData) {
        this.login = oData.login;
        this.email = oData.email;
        this.error = oData.error;
        this.submitButton = oData.submit;
        var obj = this;
        this.submitButton.onclick = function () {
            obj.submit();
        };
    },
	
    onResponse: function (oResponse) {
        switch (oResponse.transport.responseText) {
            case '0':
                // do login
                alert('New password was sent to your email');
                break;
            default:
                this.showError(oResponse.transport.responseText);
                break;
        }
    },
    
    onFailure: function (oResponse) {
        alert('[Reset] Somethig goes wrong...');
    },
    
	showError: function (sCode) {
        switch (sCode) {
	        case this.ERR_EMPTY_LOGIN:
	           this.error.innerHTML = 'Login is empty';
	           break;
	        case this.ERR_EMPTY_EMAIL:
	           this.error.innerHTML = 'Email is empty!';
	           break;
	        case this.ERR_NONEXISTENT_USER:
	           this.error.innerHTML = 'There is no user with this login and email';
	           break;
           default:
               this.error.innerHTML = 'Exception: ' + sCode;
               break;
	    }
	},
	
    /**
    * @method
    * @description
    */ 
	check: function () {
		// this should validate input
        return true;
	},
	
    /**
    * @method
    * @description
    */ 
	submit: function () {
		// submit action and returned result check should be made here
        if (this.check()) {
            // make request
            var obj = this;
            Service.prototype.initialize.call(this, {
                    onResponseRecieved: function (t) {obj.onResponse(t)},
                    onFailure:          function (t) {obj.onFailure(t)},
                    parameters:         {
                                          service: 'reset',
                                          login:    obj.login.value,
                                          email: obj.email.value
                                        }
                    }
            );
        }
	}
});
